import App from './App'
import api from '@/api'
//import store from '@/store'
// #ifndef VUE3

import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
Vue.prototype.$api = api
const app = new Vue({
	//store,
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import store from '@/store'


export function createApp() {
  const app = createSSRApp(App)
  app.config.globalProperties.$api = api
  app.use(store)
  
  
  app.config.globalProperties.$routerGuard = (to, from, next) => {
      const publicPages = ['/pages/login/index', '/pages/login/register']
      const isPublicPage = publicPages.includes(to.path)
      const isLoggedIn = store.state.token
      
      if (!isLoggedIn && !isPublicPage) {
        uni.redirectTo({
          url: '/pages/login/index'
        })
        return false
      }
      return true
    }
  
  
  return {
    app
  }
}
// #endif